<?php declare(strict_types=1);
/**
 * @author      xianganyall <xianganyall@gmail.com>
 * @copyright   2023-2025 owner
 **/

namespace Srv\Libs\Common;

final class CommType
{
    public const TYPE_ARRAY             = 'array';
    public const TYPE_OBJECT            = 'object';
    public const TYPE_VOID              = 'void';
    public const TYPE_BOOLEAN           = 'boolean';
    public const TYPE_NULL              = 'null';
    public const TYPE_DOUBLE            = 'double';
    public const TYPE_FLOAT             = 'float';
    public const TYPE_INTEGER           = 'integer';
    public const TYPE_STRING            = 'string';
    public const TYPE_RESOURCE          = 'resource';

    /**
     * @param $var
     * @return string
     * getVarType
     */
    public static function getVarType($var):string
    {
        return strtolower(gettype($var));
    }

    /**
     * @param $var
     * @return bool
     * isArray
     */
    public static function isArray($var):bool
    {
        return self::getVarType($var) === self::TYPE_ARRAY;
    }

    /**
     * @param $var
     * @return bool
     * isObject
     */
    public static function isObject($var):bool
    {
        return self::getVarType($var) === self::TYPE_OBJECT;
    }

    /**
     * @param $var
     * @return bool
     * isVoid
     */
    public static function isVoid($var):bool
    {
        return self::getVarType($var) === self::TYPE_VOID;
    }

    /**
     * @param $var
     * @return bool
     * isResource
     */
    public static function isResource($var):bool
    {
        $varType = self::getVarType($var);
        return strpos($varType, self::TYPE_RESOURCE) !== false;
    }

    /**
     * @param $var
     * @return bool
     * isBool
     */
    public static function isBool($var):bool
    {
        return self::getVarType($var) === self::TYPE_BOOLEAN;
    }

    /**
     * @param $var
     * @return bool
     * isNull
     */
    public static function isNull($var):bool
    {
        return self::getVarType($var) === self::TYPE_NULL;
    }

    /**
     * @param $var
     * @return bool
     * isFloat
     */
    public static function isFloat($var):bool
    {
        $varType = self::getVarType($var);
        return $varType === self::TYPE_DOUBLE || $varType === self::TYPE_FLOAT;
    }

    /**
     * @param $var
     * @return bool
     * isInteger
     */
    public static function isInteger($var):bool
    {
        return self::getVarType($var) === self::TYPE_INTEGER;
    }

    /**
     * @param $var
     * @return bool
     * isString
     */
    public static function isString($var):bool
    {
        return self::getVarType($var) === self::TYPE_STRING;
    }
}